﻿package mortal.game.view.fashionOnline.view
{
    import __AS3__.vec.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import flash.display.*;
    import flash.events.*;
    import flash.utils.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.view.fashionOnline.data.*;
    import mortal.mvc.core.*;

    public class FashionTagListView extends GSprite
    {
        private var _fashionTagVec:Vector.<FashionTagSpr>;
        private var _alertWin:Sprite;

        public function FashionTagListView()
        {
            this._fashionTagVec = new Vector.<FashionTagSpr>;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            var _loc_2:FashionTagSpr = null;
            super.createDisposedChildrenImpl();
            var _loc_1:int = 1;
            while (_loc_1 <= 8)
            {
                
                _loc_2 = UICompomentPool.getUICompoment(FashionTagSpr);
                _loc_2.type = _loc_1;
                _loc_2.x = 0;
                _loc_2.y = 62 * (_loc_1 - 1);
                this.addChild(_loc_2);
                this._fashionTagVec.push(_loc_2);
                this.pushUIToDisposeVec(_loc_2);
                _loc_2.configEventListener(MouseEvent.CLICK, this.onClickHandler);
                _loc_1++;
            }
            return;
        }// end function

        private function onClickHandler(event:MouseEvent) : void
        {
            var _loc_2:FashionTagSpr = null;
            var _loc_3:FashionOnlineData = null;
            for each (_loc_2 in this._fashionTagVec)
            {
                
                if (event.target == _loc_2)
                {
                    if (!_loc_2.isSelected)
                    {
                        _loc_2.isSelected = true;
                        _loc_3 = new FashionOnlineData();
                        _loc_3.fashionType = _loc_2.type;
                        _loc_3.fashionState = _loc_2.fashionState;
                        Dispatcher.dispatchEvent(new DataEvent(EventName.FashionOnlineSwitchTag, _loc_3));
                    }
                    continue;
                }
                _loc_2.isSelected = false;
            }
            return;
        }// end function

        public function selFashionByType(param1:int) : void
        {
            var _loc_2:FashionTagSpr = null;
            var _loc_3:FashionOnlineData = null;
            for each (_loc_2 in this._fashionTagVec)
            {
                
                if (param1 == _loc_2.type)
                {
                    _loc_2.isSelected = true;
                    _loc_3 = new FashionOnlineData();
                    _loc_3.fashionType = _loc_2.type;
                    _loc_3.fashionState = _loc_2.fashionState;
                    Dispatcher.dispatchEvent(new DataEvent(EventName.FashionOnlineSwitchTag, _loc_3));
                }
            }
            return;
        }// end function

        public function updateFashionTakeState() : void
        {
            var _loc_2:FashionTagSpr = null;
            var _loc_3:* = undefined;
            var _loc_1:* = Cache.instance.fashionOnline.getFashionOnlineDic();
            for each (_loc_2 in this._fashionTagVec)
            {
                
                _loc_2.fashionState = FashionOnlineConst.FashionState_Untake;
                for (_loc_3 in _loc_1)
                {
                    
                    if (_loc_2.type == _loc_3)
                    {
                        _loc_2.fashionState = _loc_1[_loc_3] as int;
                        break;
                    }
                }
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._fashionTagVec.length = 0;
            return;
        }// end function

    }
}
